<?php
/**
 * Created by JetBrains PhpStorm.
 * File: UserModel.class.php
 * User: Xnfy520@gmail.com
 * Date: 12-3-10
 * Time: 下午11:21
 */

	class UserModel extends RelationModel{

		protected $_link = array(

			'RoleUser' => array(
				'mapping_type'=>HAS_ONE,
				'mapping_name'=>'roleuser',
				'class_name'=>'RoleUser',
				'foreign_key'=>'user_id',
			),

		);

		protected $_validate = array(
			array('username', 'require', '用户名不能为空', 1, 'regex', 1),
			array('password', 'require','密码不能为空', 1, 'regex', 1),
			array('email', 'require', '电子邮箱不能为空', 1),
			array('nickname', 'require', '用户昵称为能为空', 1),
		);

		protected $_auto = array(
			array('reg_date', 'time', 1, 'function'),
			array('last_login_date', 'time', 3, 'function'),
			array('reg_ip', '_getIP', 1, 'callback'),
			array('last_login_ip', '_getIP', 3, 'callback'),
			array('password','md5',1,'function'),
		);

		protected function _getIP(){
			return $_SERVER['REMOTE_ADDR'];
		}


	}